var monk = require('monk');
var db = monk('59.110.159.213:27017/cxy');
db.then(function  (result) {
	console.log('连接成功');
});

db.catch(function  (error) {
	console.log(error);
});

function check (docName) {
	if (db.get(docName) == undefined) {
		console.log('没有'+docName+'表');
		return undefined;
	} else {
		return db.get(docName);
	}
}

var dbmanager = {
	find:function(docName,info) {
		var doc = check(docName);
		return doc.find(info);
	},
	
	findAll:function (docName,obj) {
		var doc = check(docName);
		return doc.find({},obj);
	},

	insert:function (docName,info) {
		var doc = check(docName);
		return doc.insert(info);
	},
	update:function (docName,info) {

	},
	remove:function (docName,info) {

	}
}

module.exports = dbmanager;